$(document).ready(function() {

  var xhtml = $('#awplus_content td center').html().replace(/^.*?<br>(.*)$/mg, '$1');

  var members = $.cookie('ap_memberlist').split('|');
  var id = parseInt(document.location.href.match(/id=([0-9]+)$/)[1]);

  var html = '<div style="margin: 10px;"><select id="ap_memberlist">\n';
  var m, sel;
  for (var i = 0; i < members.length; i++) {
    m = members[i].split(':');
    sel = (m[0] == id) ? 'selected="selected"' : '';
    html += '<option value="'+m[0]+'" '+sel+'>'+m[1]+'</option>\n';
  }
  html += '</select></div>';

  $('table:eq(1) td center').html(html + xhtml);

  if (id > 0) {
   $('#ap_memberlist').before('<a style="margin: 10px;" href="?id='+(id-1)+'">&lt;&lt;</a>');
  }

  if (id < members.length-1) {
    $('#ap_memberlist').after('<a style="margin: 10px;" href="?id='+(id+1)+'">&gt;&gt;</a>');
  }

  $('#ap_memberlist').change(function() {
    document.location = document.location.href.match(/^(.*?=)[0-9]+$/)[1] + $(this).val();
  });

});

